RUM_THel_landwaypoint = {
	_mkrname = _this select 0;

	_markerpos = getmarkerpos _mkrname;
	_helo_marker_distance = _markerpos distance [getPos _helo select 0, getPos _helo select 1, 0];
	_dist1 = round _helo_marker_distance;

	_grp = _this select 1;
	_pos = _markerpos;
	_stg = "RUM_THel_land = '"+(format ["%1",_helo]+"'");

	[_helo, _dist1, _mkrname, _callsign] spawn {
		_helo = _this select 0;
		_dist1 = _this select 1;
		_mkrname = _this select 2;
		_callsign = _this select 3;
		_distchk = true;

		_markerpos = getmarkerpos _mkrname;
		_helo_marker_distance = _markerpos distance [getPos _helo select 0, getPos _helo select 1, 0];

		while {_distchk} do {
			if ((_helo_marker_distance) <= 20) then{
				_distchk = false;
			}else{
				If (!alive _helo) then {
					player sidechat "Helo has crashed or has been shot down.";
					_distchk = false;
					exit;	
				}else{
					_helo_marker_distance = (_markerpos distance [getPos _helo select 0, getPos _helo select 1, 0]);
					_helo_height = (getPos _helo select 2);
					player sidechat format ["%1 this is %2, we are %3 meters from your LZ - OVER",RUM_COM_Callsign, _callsign, round _helo_marker_distance];
					sleep 45;
				};
			};
		};
	};
	
		// player sidechat format["Land - %1",_pos];
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointStatements ["true", _stg];
		_wp setWaypointType "MOVE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointCompletionRadius 100;



		if(RUM_THEL_invisibleH)then{_lz = createVehicle ["HeliHEmpty", _pos, [], 0, "NONE"]};
		_lz;
};

RUM_THel_movewaypoint = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	// player sidechat format["Count: %1",count _this];
	if(count _this == 2)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
	// player sidechat format["move - %1",_pos];
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointType "MOVE";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointBehaviour "CARELESS";
		_wp setWaypointCompletionRadius 50;
		_wp setWaypointStatements ["true", ""];
		_helo flyInHeight RUM_THEL_flyHeight;
		if(RUM_THel_Special == "Para Drop")then{_helo FlyInHeight RUM_THEL_flyHeightPara};
		if(RUM_THel_Special == "HALO Jump")then{_helo FlyInHeight RUM_THEL_flyHeightHALO};

};
RUM_THel_moveWPNormal = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if(count _this == 2)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
	_heloTakeOff2 = true;			
	while {_heloTakeOff2} do {
		_distanceToDeck = round(getposASL _helo select 2);
		_heightToHomePlate = (_distanceToDeck - (getposASL _home select 2));
		_distToHomePlate = round( _helo distance _home);
		if (_distToHomePlate >= 55) then {
			deleteWaypoint [_grp, 0];
			_wp=_grp addWaypoint [_pos, 0];
			_wp setWaypointType "MOVE";
			_wp setWaypointCombatMode "BLUE";
			_wp setWaypointSpeed "NORMAL";
			_wp setWaypointBehaviour "CARELESS";
			_wp setWaypointCompletionRadius 100;
			_helo flyInheight 45;

			sleep 5;
			_helo flyInheight RUM_THEL_flyHeight;
			_heloTakeOff2 = false;
		};
	};
};

RUM_THel_moveWPTakeoff = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if(count _this == 2)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
			player sidechat "in if statement of MoveWP Takeoff";

	if (_class == "MV22") then {
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointType "MOVE";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointBehaviour "CARELESS";
		_wp setWaypointCompletionRadius 0;
		_helo flyInheight 60;
	}else{
			player sidechat "bypassed mv22, in else";
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointType "MOVE";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointBehaviour "CARELESS";
		_wp setWaypointCompletionRadius 100;
		_helo flyInheight 18;
	};
};
RUM_THel_moveWPLZDustOff = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if(count _this == 2)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
	if (_class == "MV22") then {
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointType "MOVE";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointBehaviour "CARELESS";
		_wp setWaypointCompletionRadius 0;
		_helo flyInheight 60;
	}else{
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointType "MOVE";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointBehaviour "CARELESS";
		_wp setWaypointCompletionRadius 50;
		_helo flyInheight 22;
	};
};
RUM_THel_moveWPLZDustOffNormal = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if(count _this == 2)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
	_heloDustOff2 = true;			
	while {_heloDustOff2} do {
		_distFromDustOff = round( _helo distance _pos);
		if (_distFromDustOff >= 100) then {
			deleteWaypoint [_grp, 0];

			_wp=_grp addWaypoint [_pos, 0];
			_wp setWaypointType "MOVE";
			_wp setWaypointCombatMode "BLUE";
			_wp setWaypointSpeed "NORMAL";
			_wp setWaypointBehaviour "CARELESS";
			_wp setWaypointCompletionRadius 100;
			_helo flyInheight 45;
			_heloDustOff2 = false;
		};
	};
};
RUM_THel_LandHome = {
	if (surfaceIsWater (getpos _home)) then {
		// player sidechat format["Heli is on LHD or Ship, %1",_heliRoute];

		_heloRTBWaypoint = true;
		
		while {_heloRTBWaypoint} do {
			sleep .05;
			_distanceToIngress = round(_ingress distance _helo);
			// hintsilent format["distance from home plate: %1",_distanceToIngress];
			if (_distanceToIngress <=160) then {
				_lz = createVehicle ["HeliHEmpty", getposASL _home, [], 0, "NONE"];
				_lz setposASL getPosASL _home;




				_wp=_grp addWaypoint [getposASL _lz, 0];
				_wp setWaypointType "GETOUT";
				_wp setWaypointSpeed "LIMITED";
				_wp setWaypointBehaviour "CARELESS";
				_wp setWaypointCombatMode "BLUE";


				_wp setWaypointCompletionRadius 0;
				_helo flyInheight (RUM_THEL_flyHeight -35);
				_stg = "RUM_THel_endflight = '"+(format ["%1",_helo])+"'";
				_wp setWaypointStatements ["true", _stg];
				// _lz;
				
				// ends the while loop
				_heloRTBWaypoint = false;
			};
		};
		
		// starts new while loop for landing procedures...
		_heloRTBWaypointH = true;
		
		while {_heloRTBWaypointH} do {
			sleep .05;
			_distanceToDeck = round(getposASL _helo select 2);
			_heightToHomePlate = round((getposASL _helo select 2) - (getposASL _home select 2));
			_distToHomePlate = round( _helo distance _home);
			if (_distToHomePlate <= 70) then {
				if (_heightToHomePlate <= 0.5) then {
				sleep 3;
				_helo setFuel 0;
				sleep 5;

				// ends the while loop.
				_heloRTBWaypointH = false;
				}else{
					// hintsilent format ["Height Above Home Plate: %1",_heightToHomePlate];
				};
			}else{
				// hintsilent format ["Distance to Home Plate: %1",_distToHomePlate];
			};
		};
	}else{

		// This section of the if statment is for land based helo's
		// player sidechat format["Heli is not over water, %1",_heliRoute];
		// waits till closer to ingress position before moving to final approach.
		waituntil{((_ingress distance [getPos _helo select 0, getPos _helo select 1, 0]) <= 200)};

		_wp=_grp addWaypoint [getpos _home, 0];
		_wp setWaypointType "GETOUT";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointBehaviour "CARELESS";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointCompletionRadius 50;
		_helo flyInheight (RUM_THEL_flyHeight - 45);
		_stg = "RUM_THel_endflight = '"+(format ["%1",_helo])+"'";
		_wp setWaypointStatements ["true", _stg];

	};
};

RUM_THel_Spawn = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if(count _this == 2)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
	// _wp=_grp addWaypoint [getpos _spwn, 0];
	_wp=_grp addWaypoint [_pos, 0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointCombatMode "BLUE";
	_wp setWaypointCompletionRadius 50;
};

RUM_THel_VehicleOptions = {
	// these options are timed for the CH53, although simlar to other classnames, each vehicle option is tuned to its own delays to make animations look better.
	if (_class == "MV22") then {
	// player sidechat "MV22 Options";
		[_helo] spawn {
			_helo = _this select 0;
			_vehOption = true;
			_vehOption1 = true;
			_vehOption2 = false;
			while {_vehOption} do {
				sleep 1;
				_helo_height = round (getPos _helo select 2);
				// hintsilent format ["Altitude: %1", _helo_height];
				if (_vehOption1)then{
					if (((getPos _helo select 2) <= 4)) then {
						// player sidechat "Opening Ramp & Doors";
						_helo animate ["ramp_top",1];
						_helo animate ["ramp_bottom",1];
						sleep 3;
						_helo animate ["door1_top", 1];
						_helo animate ["door1_bottom", 1];
						_vehOption1 = false;
						_vehOption2 = true;
					};
				};
				if (_vehOption2)then{
					if (((getPos _helo select 2) >= 4)) then {
						// player sidechat "closing doors & Ramp";
						_helo animate ["door1_top", 0];
						_helo animate ["door1_bottom", 0];
						sleep 3;
						_helo animate ["ramp_top",0];
						_helo animate ["ramp_bottom",0];
						_vehOption = false;
						_vehOption2 = false;
					};
				};
			};
		};
		// this will be for the HALO/Para ramp to open before exit... 
		// if(RUM_THel_Special == "HALO Jump")then{
		// _helo FlyInHeight RUM_THEL_flyHeightHALO;
		// };

	};
	if (_class == "USEC_ch53_E") then {
	// player sidechat "CH53 Options";
		[_helo, _ingress] spawn {
			_helo = _this select 0;
			_ingress = _this select 1;
			_vehOption = true;
			_vehOption1 = true;
			_vehOption2 = false;
			while {_vehOption} do {
			// this animate ["ramp_bottom",0];this animate ["ramp_top",0];
				sleep 1;
				_helo_height = round (getPos _helo select 2);
				// hintsilent format ["Altitude: %1", _helo_height];
				if (_vehOption1)then{
					if (((getPos _helo select 2) <= 6)) then {
						// player sidechat "Opening Ramp";
						_helo animate ["ramp_top",1];
						_helo animate ["ramp_bottom",1];
						_vehOption1 = false;
						_vehOption2 = true;
					};
					// should lower the gear once it reached the _ingress point to land
					_distToIngress = round(_ingress distance _helo);
					// hintsilent format["distance from home plate: %1",_distToIngress];
					if (_distToIngress <=160) then {
						// player sidechat "Lowering Gear";
						[_helo] execvm "\usec_ch53\scripts\ch53_geardown.sqf";
					};
				};
				if (_vehOption2)then{
					if (((getPos _helo select 2) >= 4)) then {
						// player sidechat "Closing Ramp";
						_helo animate ["ramp_top", 0];
						_helo animate ["ramp_bottom", 0];
						sleep 4;
						// player sidechat "Raising Gear";
						[_helo] execvm "\usec_ch53\scripts\ch53_gearup.sqf";
						_vehOption = false;
						_vehOption2 = false;
					};
				};
			};
		};
		// this will be for the HALO/Para ramp to open before exit... 
		// if(RUM_THel_Special == "HALO Jump")then{
		// _helo FlyInHeight RUM_THEL_flyHeightHALO;
		// };

	};
};
